package cn.hh.schedule;

import cn.hh.sendall.MyWebsocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author huangh
 * @date 2021/07/28
 * @Description:
 */
@Component
public class Scheduler{
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    @Autowired
    private MyWebsocketServer myWebsocketServer;

    //每隔2秒执行一次
    @Scheduled(fixedRate = 2000)
    public void testTasks() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));
        myWebsocketServer.sendAll(dateFormat.format(new Date()));
    }

    //每天3：05执行
    @Scheduled(cron = "0 1/60 * * * ?")
    public void testTasks2() {
        System.out.println("定时任务执行时间：" + dateFormat.format(new Date()));

    }


}
